﻿@model Doan.Website.Models.Comment
@using CaptchaMvc.HtmlHelpers
@using System.Globalization


@if (ViewBag.ErrorCaptcha != null)
{
    <div class="alert alert-block fade in alert-error alert-error">
        <a href="#" data-dismiss="alert" class="close">&times;</a>
        @ViewBag.ErrorCaptcha
    </div>
}

@if (ViewBag.OnePageOfComment.PageCount!=0)
{
    <fieldset class="showComment"> 
        <legend>Các bình luận</legend>
        @foreach (var item in ViewBag.OnePageOfComment)
        {
            <div class="comment clearfix" id="cm-@item.CommentId">
                <div class="cm-info">
                    <div class="AuthorName">
                        <span style="font-weight: normal; color: deepskyblue">Gửi bởi:</span> @item.AuthorName
                    </div>
                    <div class="emailComment">Email: @item.Email</div>
                    <div class="dateComment">@item.Date</div> 
                    @if (Request.IsAuthenticated)
                    {
                        <div>
                            @Ajax.ActionLink("Xoa Comment", "DeleteComment", "Share", new { id = item.CommentId }, new AjaxOptions
                                                                                                    {
                                                                                                        Confirm = "Bạn có chắc chấn muốn xóa bài này?",
                                                                                                        UpdateTargetId = "cm-"+item.CommentId
                                                                                                    })
                        </div>
                    }
                </div>  
                <div class="cm-main">
                    <div class="titleComment">@item.Title</div>
                    <div class="contentComment">@item.Content</div>
                </div>  
            </div>
        }

        <div>
            <div class="btn-page">
                @Ajax.ActionLink("Đầu", "Index", new { page = 1 }, new AjaxOptions { UpdateTargetId = "Comment" })
                @Ajax.ActionLink("<", "Index", new { page = ViewBag.OnePageOfComment.PageNumber - 1 }, new AjaxOptions { UpdateTargetId = "Comment" })
                @for (int i = 1; i <= ViewBag.OnePageOfComment.PageCount; i++)
                {
                    var page = i.ToString(CultureInfo.InvariantCulture);
                    @Ajax.ActionLink(page, "Index", new { page = i }, new AjaxOptions { UpdateTargetId = "Comment" }, new { @id = "cmpage" + page })
                }
                @Ajax.ActionLink(">", "Index", new { page = ViewBag.OnePageOfComment.PageNumber + 1 }, new AjaxOptions { UpdateTargetId = "Comment" })
                @Ajax.ActionLink("Cuối", "Index", new { page = ViewBag.OnePageOfComment.PageCount }, new AjaxOptions { UpdateTargetId = "Comment" })
            </div>
        </div>
    </fieldset>
    }
    
<script>
    $(document).ready(function () {
        var page = @ViewBag.pageNumber;
        var id = "cmpage" + page;
        $(".btn-page a").removeClass("active");
        $('#' + id).addClass('cmpageActive');
    });
</script>    

@using (Ajax.BeginForm("CreateComment", "Share", new AjaxOptions()
{
    UpdateTargetId = "Comment",
    HttpMethod = "Post",
}))
{       
    @Html.ValidationSummary(true)
    <fieldset class="createComment">
        <legend>Gửi bình luận</legend>
        <div class="editor-label ">
            <span>Họ tên</span>
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.AuthorName)
            @Html.ValidationMessageFor(model => model.AuthorName)
        </div>
        <div class="editor-label">
            <span>Email</span>
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)
        </div>
        <div class="editor-label">
            <span>Tiêu đề</span>
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>
        <div class="editor-label">
            <span>Nội dung</span>
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Content)
            @Html.ValidationMessageFor(model => model.Content)
        </div>
        <div class="editor-label">
            <span>Mã xác thực</span>
        </div>
        <div class="editor-field">
            @Html.Captcha("Đổi mã khác", "Nhập vào mã xác thực", 4, "Is required field.")
            @ViewBag.ErrorMessage
        </div>
        <input type="hidden" name="MaBaiViet" value="@ViewBag.Id" />
        <p class="btncomment">
            <input type="submit" value="Gửi Comment" class="btn btn-success btn-large" />
        </p>
    </fieldset>
}

